#include "heap.h"

void test()
{
	int arr[] = { 4,5,8,1,3,10,7,2,9,6, };
	HP hp;
	HeapInit(&hp);
	int len = sizeof(arr) / sizeof(int);
    int i = 0;
	for (i = 0; i < len; i++)
	{
		HeapPush(&hp,arr[i]);
	}
	HeapPrint(&hp);

	while (!HeapEmpty(&hp))
	{
		printf("%d\n", HeapTop(&hp));
		HeapPop(&hp);
	}
	HeapDestoy(&hp);
}

void HeapSort(int* arr,int len)
{
    int i = 0;
	for (i = 0; i < 10; i++)
	{
		AdjustUp(arr,i);
	}
	int end = len-1;
	while (end)
	{
		Swap(&arr[0],&arr[end]);
		AdjustDown(arr,end,0);
		end--;
	}
}

int main()
{
	test();
	int arr[] = { 4,5,8,1,3,10,7,2,9,6, };
	int len = sizeof(arr) / sizeof(int);
	HeapSort(arr,len);
	HP hp;
	HeapInitArray(&hp,arr,len);
	HeapPrint(&hp);
    int i = 0;
	for (i = 0; i < len; i++)
	{
		printf("%d ",arr[i]);
	}
	return 0;
}
